package com.cat.net.network.kafka;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * kafka 配置
 */
@Configuration
public class KafkaConfig {

    @Value("${kafka.bootstrap-servers:}")
    private String bootstrapServers;

//    @Value("${kafka.key-serializer}")
//    private String keySerializer;
//
//    @Value("${kafka.value-serializer}")
//    private String valueSerializer;

    @Value("${kafka.retries:3}")
    private int retries;

    @Value("${kafka.linger:5}")
    private int linger;

    @Value("${kafka.group-id:}")
    private String groupId;

    @Value("${kafka.auto-offset-reset:earliest}")
    private String autoOffsetReset;

    @Value("${kafka.listener.ack-mode:manual}")
    private String ackMode;

    @Value("${kafka.listener.concurrency:3}")
    private int concurrency;

    @Value("${kafka.listener.partition:3}")
    private int partition;

    @Value("${kafka.listener.replication-factor:1}")
    private short replicationFactor;

    public String getBootstrapServers() {
        return bootstrapServers;
    }

    public void setBootstrapServers(String bootstrapServers) {
        this.bootstrapServers = bootstrapServers;
    }

    public int getRetries() {
        return retries;
    }

    public void setRetries(int retries) {
        this.retries = retries;
    }

    public int getLinger() {
        return linger;
    }

    public void setLinger(int linger) {
        this.linger = linger;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    //    public String getKeySerializer() {
//        return keySerializer;
//    }
//
//    public void setKeySerializer(String keySerializer) {
//        this.keySerializer = keySerializer;
//    }
//
//    public String getValueSerializer() {
//        return valueSerializer;
//    }
//
//    public void setValueSerializer(String valueSerializer) {
//        this.valueSerializer = valueSerializer;
//    }

    public String getAutoOffsetReset() {
        return autoOffsetReset;
    }

    public void setAutoOffsetReset(String autoOffsetReset) {
        this.autoOffsetReset = autoOffsetReset;
    }

    public String getAckMode() {
        return ackMode;
    }

    public void setAckMode(String ackMode) {
        this.ackMode = ackMode;
    }

    public int getConcurrency() {
        return concurrency;
    }

    public void setConcurrency(int concurrency) {
        this.concurrency = concurrency;
    }

    public int getPartition() {
        return partition;
    }

    public void setPartition(int partition) {
        this.partition = partition;
    }

    public short getReplicationFactor() {
        return replicationFactor;
    }

    public void setReplicationFactor(short replicationFactor) {
        this.replicationFactor = replicationFactor;
    }

//    @Bean
//    public KafkaProducer<String, Packet> kafkaProducer() {
//        Properties props = new Properties();
//        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
//        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, keySerializer);
//        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, valueSerializer);
//        props.put(ProducerConfig.RETRIES_CONFIG, retries);
//        props.put(ProducerConfig.LINGER_MS_CONFIG, linger);
//        return new KafkaProducer<>(props);
//    }
//
//    @Bean
//    public KafkaConsumer<String, Packet> kafkaConsumer() {
//        Properties props = new Properties();
//        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
//        props.put(ConsumerConfig.GROUP_ID_CONFIG, consumerGroupId);
//        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, keySerializer);
//        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, valueSerializer);
//        props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset);
//        return new KafkaConsumer<>(props);
//    }

}
